export default function walk(node,{enter,leave}){
  visit(node,null,enter,leave)
}
function visit(node,parent,enter,leave){
  if(enter && node && node.type){
    enter(node,parent)
  }
  if(node && node.type){
    let childKeys = Object.keys(node).filter((key)=>{
      return typeof node[key] === 'object';
    })

    childKeys.forEach(key=>{
      let child = node[key];
      if(Array.isArray(child)){
        child.forEach(val=>visit(val,node,enter,leave))
      }else if(child && child.type){
        visit(child,node,enter,leave)
      }
    })
  }
  if(leave && node && node.type){
    leave(node,parent)
  }
}